&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v9r12
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Include 
/*------------------------------------------------------------------------
    File        : 
    Purpose     :

    Syntax      :

    Description :

    Author(s)   :
    Created     :
    Notes       :
  ----------------------------------------------------------------------*/
/*          This .W file was created with the Progress AppBuilder.      */
/*----------------------------------------------------------------------*/

/* ***************************  Definitions  ************************** */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */



/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME



/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: Include
   Allow: 
   Frames: 0
   Add Fields to: Neither
   Other Settings: INCLUDE-ONLY
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB) 
  CREATE WINDOW Include ASSIGN
         HEIGHT             = 15
         WIDTH              = 60.
/* END WINDOW DEFINITION */
                                                                        */
&ANALYZE-RESUME

 


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Include 


/* ***************************  Main Block  *************************** */

IF get-field("monnaie") <> doce.codmon       AND 
  (doce.noadrf = 1000 OR doce.noadrf = 1001) THEN DO:
   flag-monnaie = TRUE.
   doce.codmon  = get-field("monnaie").
   IF doce.codmon = "EUR" THEN ASSIGN doce.noadrl = 1000
                                      doce.noadrf = 1000.
   ELSE ASSIGN doce.noadrl = 1001
               doce.noadrf = 1001.

   FIND adrd WHERE adrd.nosoc = doce.nosoc
               AND adrd.noadr = doce.noadrl
               AND adrd.csmt  = doce.csmtl NO-LOCK NO-ERROR.

   ASSIGN doce.taux   = adrd.codicha
          doce.codmon = adrd.codmon
          doce.heure  = TIME
          doce.dval   = TODAY
          doce.datdoc = TODAY
          doce.totme  = 0
          doce.totmtn = 0
          doce.totmb  = 0.

   IF doce.noadrf <> 1001 THEN DO:
      FIND FIRST mon WHERE mon.nosoc  = doce.nosoc
             AND mon.codmon = doce.codmon
             AND mon.boucl  = ""
             AND mon.datc  <= doce.datdoc NO-LOCK NO-ERROR.
      IF AVAILABLE mon THEN ASSIGN doce.cours = mon.cours
                                   doce.unit  = mon.unit.
      ELSE ASSIGN doce.cours = 1
                  doce.unit  = 1.
   END.
   ELSE ASSIGN doce.cours = 1
               doce.unit  = 1.

END.

FOR EACH docld WHERE docld.nosoc  = doce.nosoc
                 AND docld.typdoc = doce.typdoc
                 AND docld.prefix = doce.prefix
                 AND docld.nodoc  = doce.nodoc:


    IF docld.ref = "" AND docld.norub = "" THEN NEXT.

    IF docld.ref <> "" THEN buf-qte = INTEGER(get-field("qtes" + STRING(docld.noseq))).
    ELSE buf-qte = 1.

    IF buf-qte = docld.qtec AND NOT flag-monnaie THEN NEXT.

    IF NOT flag-monnaie THEN ASSIGN doce.totmtn = doce.totmtn - docld.montne
                                                - IF docld.taxi THEN 0 ELSE docld.montx
                                    doce.totqte = doce.totqte - docld.montx.

    IF buf-qte = 0 THEN DO:

       FOR EACH dliv WHERE dliv.nosoc  = docld.nosoc
                       AND dliv.typdoc = docld.typdoc
                       AND dliv.prefix = docld.prefix
                       AND dliv.nodoc  = docld.nodoc
                       AND dliv.noseq  = docld.noseq:
           DELETE dliv.
       END.

       FOR EACH docli WHERE docli.nosoc  = docld.nosoc
                        AND docli.typdoc = docld.typdoc
                        AND docli.prefix = docld.prefix
                        AND docli.nodoc  = docld.nodoc
                        AND docli.noseq  = docld.noseq:
           DELETE docli.
       END.

       FOR EACH docnom WHERE docnom.nosoc  = docld.nosoc
                         AND docnom.typdoc = docld.typdoc
                         AND docnom.prefix = docld.prefix
                         AND docnom.nodoc  = docld.nodoc
                         AND docnom.noseq  = docld.noseq:
           DELETE docnom.
       END.
       DELETE docld.

       ASSIGN doce.totme   = doce.totmtn
              doce.totmb   = doce.totme * doce.cours / doce.unit.
       NEXT.

    END.

    docld.qteumq = buf-qte.
    docld.qtec   = docld.qteumq.
    docld.qteumb = docld.qtec.
    docld.solde  = docld.qtec.

    RUN calcul_mtligne.

END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


